<style lang="less">
@import "@/styles/table-common.less";
.btn-box {
  // padding: 10px 12px 10px 0;
  height: 32px;
  display: flex;
  align-items: center;
  span {
    margin-left: 15px;
  }
}
.detail-modal {
  .form {
    div {
      display: flex;
      margin-bottom: 10px;
      span {
        width: 130px;
      }
      input {
        flex: 1;
        border: 1px solid #e8eaec;
        outline: none;
        text-indent: 16px;
        color: #515a6e;
      }
    }
  }
  .refund-num {
    margin-top: 15px;
  }
}
.statistic{
  display: flex;
  margin-bottom: 20px;
  li{
    margin-right: 20px;
  }
}
</style> 
<template>
  <div class="search">
    <Card>
      <Form ref="searchForm" :model="searchForm" inline :label-width="100">
        <Row v-show="openSearch" @keydown.enter.native="handleSearch">
            <FormItem label="企业性质：">
                <Select v-model="searchForm.orderType" transfer placeholder="请选择" @on-change="changeOrderType" style="width: 200px">
                    <Option value="3" label="共享会议室订单">共享会议室订单</Option>
                    <Option value="9" label="云打印订单">云打印订单</Option>
                    
                </Select>
            </FormItem>
            <FormItem label="名称：">
                <Input v-model="searchForm.companyName" placeholder="请输入" />
            </FormItem>
            <FormItem label="订单发起时间">
            <DatePicker
                :options="options"
                v-model="selectDate"
                type="daterange"
                format="yyyy-MM-dd"
                clearable
                @on-change="selectDateRange"
                placeholder="选择起始时间"
                style="width: 200px"
            ></DatePicker>
            </FormItem>
            <FormItem style="margin-left: -35px" class="br">
            <Button @click="handleSearch" type="primary" icon="ios-search"
                >搜索</Button
            >
            <Button @click="handleReset">重置</Button>
            </FormItem>
        </Row>
      </Form>
      <Table
        :loading="loading"
        border
        :columns="columns"
        :data="data"
        sortable="custom"
        ref="table"
      >
      </Table>
      <Row type="flex" justify="end" class="page">
        <Page
          :current="searchForm.pageNumber"
          :total="total"
          :page-size="searchForm.pageSize"
          @on-change="changePage"
          @on-page-size-change="changePageSize"
          :page-size-opts="[10, 20, 50]"
          size="small"
          show-total
          show-elevator
          show-sizer
        ></Page>
      </Row>
    </Card>
    <Modal
        v-model="modal"
        title="详情"
        @on-ok="ok"
        @on-cancel="cancel">
        <div class="detail-modal">
          <div class="form">
            <div><span>订单编号</span><input type="text" readonly :value="detailData.orderNo"></div>
            <div><span>发起人姓名</span><input type="text" readonly :value="detailData.realName"></div>
            <div><span>发起时间</span><input type="text" readonly :value="detailData.createTime"></div>
            <div><span>取消原因</span><input type="text" readonly :value="detailData.refundReasonWapExplain"></div>
          </div>
        </div>
        <div slot="footer">
        </div>
    </Modal>
  </div>
</template>
<script>
import { getScOrderByCondition } from "@/api/index";
import { shortcuts } from "@/libs/shortcuts";
import columnObj from "./column"
export default {
  name: "user-manage",
  props: ["uid","expenseId"],
  data() {
    return {
      message: "",
      height: 510,
      showUser: false,
      showType: "0",
      loading: true,
      selectDate: "",
      openSearch: true,
      idenList: [], //角色状态
      options: {
        shortcuts: shortcuts,
      },
      
      searchForm: {
        pageNumber: 1,
        pageSize: "10",
        sort: "createTime",
        order: "desc",
        orderType: '3'
      },
      columns: [],
      data: [],
      statistic: {},
      modal: false,
      detailData: {}
    };
  },
  methods: {
    init() {
      this.getDataList();
    },
    changeSort(e) {
      this.searchForm.sort = e.key;
      this.searchForm.order = e.order;
      if (e.order == "normal") {
        this.searchForm.order = "";
      }
      this.getDataList();
    },
    getDataList() {
      this.loading = true;
      this.searchForm.uCompanyId = this.uid
      getScOrderByCondition(this.searchForm).then((res) => {
        this.loading = false;
        if (res.success) {
          this.data = res.result.content
          this.total = res.result.totalElements
          this.statistic = res.result.statistic
          if (this.data.length == 0 && this.searchForm.pageNumber > 1) {
            this.searchForm.pageNumber -= 1;
            this.getDataList();
          }
        }
      });
    },

    changePage(v) {
      this.searchForm.pageNumber = v;
      this.getDataList();
    },
    changePageSize(v) {
      this.searchForm.pageSize = v;
      this.getDataList();
    },
    selectDateRange(v) {
        console.log(v)
      if (v) {
        this.searchForm.startDate = v[0];
        this.searchForm.endDate = v[1];
      }
    },
    handleSearch() {
      this.searchForm.pageNumber = 1;
      this.searchForm.pageSize = 10;
      this.getDataList();
    },
    handleReset() {
      this.selectDate = "";
      this.searchForm.startDate = "";
      this.searchForm.endDate = "";
      this.searchForm.orderType = "3";
      this.searchForm.companyName = "";
      this.searchForm.pageNumber = 1;
      this.searchForm.pageSize = 10;
      // 重新加载数据
      this.getDataList();
    },
    changeOrderType(e) {
        this.columns = columnObj[this.searchForm.orderType]
        this.searchForm.startDate = "";
        this.searchForm.endDate = "";
        this.searchForm.orderType = e;
        this.searchForm.companyName = "";
        this.getDataList()
    }
  },
  created() {
  },
  activated() {
    this.init();
  },
  mounted() {
    // 计算高度
    this.height = Number(document.documentElement.clientHeight - 230);
    this.init();
    this.columns = columnObj[this.searchForm.orderType]
  },
};
</script>